#!/usr/bin/env python
# -*- coding: utf-8 -*-

# thirdpart modules
from PyQt5.QtCore import (
    QSize,
    Qt,
)

from PyQt5.QtGui import (
    QPixmap,
)

from PyQt5.QtWidgets import (
    QComboBox,
    QDialog,
    QDialogButtonBox,
    QGridLayout,
    QGroupBox,
    QLabel,
    QLayout,
    QLineEdit,
    QPushButton,
    QSizePolicy,
    QVBoxLayout,
)

class LogonDialog(QDialog):
    def __init__(self, parent=None):
        super().__init__(parent)

        self.label = QLabel('logo')
        self.label.setPixmap(QPixmap(':/Resources/Images/qt.png'))

        self.groupBox = QGroupBox()
        self.gridLayout = QGridLayout(self.groupBox)
        self.gridLayout.setColumnStretch(0, 3)
        self.gridLayout.setColumnStretch(1, 5)
        self.gridLayout.setColumnStretch(2, 1)

        # --------------------------------------------------
        self.labUsername = QLabel('Username', self.groupBox)
        self.gridLayout.addWidget(self.labUsername, 0, 0, Qt.AlignRight | Qt.AlignVCenter)

        self.lineUsername = QLineEdit(self.groupBox)
        self.labUsername.setBuddy(self.lineUsername)
        self.gridLayout.addWidget(self.lineUsername, 0, 1)

        self.btnBrowse = QPushButton(self.groupBox)
        sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.btnBrowse.sizePolicy().hasHeightForWidth())
        self.btnBrowse.setSizePolicy(sizePolicy)
        self.btnBrowse.setMinimumSize(QSize(20, 0))
        self.btnBrowse.setText('...')
        self.gridLayout.addWidget(self.btnBrowse, 0, 2)

        # --------------------------------------------------
        self.labPassword = QLabel('Password', self.groupBox)
        self.gridLayout.addWidget(self.labPassword, 1, 0, Qt.AlignRight | Qt.AlignVCenter)

        self.linePassword = QLineEdit(self.groupBox)
        self.linePassword.setEchoMode(QLineEdit.Password)
        self.linePassword.setInputMethodHints(Qt.ImhHiddenText| Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase)
        self.labPassword.setBuddy(self.linePassword)
        self.gridLayout.addWidget(self.linePassword, 1, 1)

        # --------------------------------------------------
        self.labDatabase = QLabel('Database', self.groupBox)
        self.gridLayout.addWidget(self.labDatabase, 2, 0, Qt.AlignRight | Qt.AlignVCenter)

        self.combDatabase = QComboBox(self.groupBox)
        self.combDatabase.setEditable(True)
        self.labDatabase.setBuddy(self.combDatabase)
        self.gridLayout.addWidget(self.combDatabase, 2, 1)

        # --------------------------------------------------
        self.labConnectAs = QLabel('Connect as', self.groupBox)
        self.gridLayout.addWidget(self.labConnectAs, 3, 0, Qt.AlignRight | Qt.AlignVCenter)

        self.combConnectAs = QComboBox(self.groupBox)
        self.combConnectAs.setEditable(False)
        self.combConnectAs.addItems(('Normal', 'SYSDBA'))
        self.combConnectAs.setDisabled(True)
        self.labConnectAs.setBuddy(self.combConnectAs)
        self.gridLayout.addWidget(self.combConnectAs, 3, 1)

        # --------------------------------------------------
        self.topLayout = QGridLayout()
        self.topLayout.setColumnMinimumWidth(0, 100)
        self.topLayout.addWidget(self.label, 0, 0, Qt.AlignHCenter | Qt.AlignVCenter)
        self.topLayout.addWidget(self.groupBox, 0, 1)

        # --------------------------------------------------
        self.buttonBox = QDialogButtonBox(self)
        self.buttonBox.setOrientation(Qt.Horizontal)
        self.buttonBox.setCenterButtons(True)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)

        # --------------------------------------------------
        self.mainLayout = QVBoxLayout()
        self.mainLayout.addLayout(self.topLayout)
        self.mainLayout.addWidget(self.buttonBox)
        self.mainLayout.addStretch(1)

        self.setLayout(self.mainLayout)
        self.setWindowTitle('Logon')
        self.layout().setSizeConstraint(QLayout.SetFixedSize)

    def getConnString(self):
        strUsername = self.lineUsername.text()
        strPassword = self.linePassword.text()
        strDatabase = self.combDatabase.currentText()
        return '%s/%s@%s' % (strUsername, strPassword, strDatabase)

if __name__ == '__main__':
    import sys
    from PyQt5.QtWidgets import QApplication

    app = QApplication(sys.argv)
    dialog = LogonDialog()
    sys.exit(dialog.exec_())
